package com.gxa.shop.servlet.carousel;

import com.alibaba.fastjson.JSON;
import com.gxa.shop.commons.r.R;
import com.gxa.shop.service.carousel.CarouselService;
import com.gxa.shop.service.carousel.impl.CarouselServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * com.gxa.shop.servlet.carousel
 * User: 刁彦侨
 * Date: 2024/12/19 10:20
 * motto:   逆水行舟不进则退
 * Description:
 * Version: V1.0
 */
@WebServlet(name = "carousel.DeleteByIdServlet", value = "/carousel/deleteById")
public class DeleteByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("carouselId");
        Integer carouselId=null;
        R r;
        try {
            carouselId = Integer.parseInt(id);
            CarouselService carouselService = new CarouselServiceImpl();
            boolean delete = carouselService.deleteCarousel(carouselId);
            r = delete? R.ok() : R.error("删除失败");
        }catch (Exception e){
            r=R.error("ID编号不正确");
        }

        PrintWriter writer = response.getWriter();
        String result = JSON.toJSONString(r);
        System.out.println("result:"+result);
        writer.write(result);
        writer.flush();
        writer.close();
    }
}
